import {WidgetClass} from "../atom/widget";

export class Matrix extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options;
    if (UI) {
      this.UI.data = UI.data;
    } else {
      this.UI.data = {
        itemSize: {
          width: 80,
          height: 80,
        },
        itemSpace:20,//水平间距
        itemVSpace:20,//垂直间距
        inputs: [],
        outputs: [],
        inputsName: "信号源",
        outputsName: "显示器",
        backgroundColor: "bg-color-page", //bg-color-page
        componentColor: "bg-color-container",
        textColor: "text-color-secondary",
        contentColor: "text-color-primary",
        activeColor: "brand-color",
        textAntiColor: "text-color-anti",
        textSize:16,
        showTopLeftValue:false,//左上角展示
        showControlValue:false,//右上角展示
        showType: "name",//右上角展示类型
      };
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      ...superState,
      values: [
        ...superState.values,
        {
          name: "当前信号源",
          key: "input",
          type: "string",
          value: null,
        },
        {
          name: "当前显示源",
          key: "output",
          type: "string",
          value: null,
        },
      ],
      events: [
        {
          name: "长按事件",
          key: `longPress-${this.id}`,
          eventType: "longPress",
          type: "event",
          value: {
            time: 1 //长按触发时间(秒)
          },
          action: [],
        },
        {
          name: "设置路由",
          key: "setRouter",
          type: "event",
          eventType: "custom",
          action: [],
        }
      ],
    };
  }
}
